<template>
	<view class="course-form-box">
		<bsNavBar title='资料填写'></bsNavBar>
		<QyForm v-if='vipType==0' :status='status' ref='QyForm' :vipTypeList='vipTypeList'></QyForm>
		<GrForm v-if='vipType==1' :vipTypeList='vipTypeList' :status='status' ref='GrForm'></GrForm>
	</view>
</template>

<script>
	import GrForm from './form/GrForm.vue'
	import QyForm from './form/QyForm.vue'
	export default {
		components: {
			GrForm,
			QyForm
		},
		data() {
			return {
				vipTypeList: [],
				status: null,
				declareId: '',
				vipType: null //先写死(当前用户是企业会员还是个人会员)
			};
		},
		async onLoad(e) {
			//0审核中.1审核通过.2审核失败
			const userType = this.cache.getCache('userMsg').userType
			this.vipType = this.cache.getCache('userMsg').userType
			console.log(e, '路由参数', userType)
			this.status = e.status
			//查询可以申报的vip
			let vipTypeList = await this.$u.api.selectVipList({
				page: 1,
				pageSize: 20,
				vipType: userType,
			})
			vipTypeList.forEach(item => {
				item.typeName = item.typeName + ' ' + item.price + '元/年'
			})
			this.vipTypeList = vipTypeList
			if (e.declareId) {
				this.declareId = e.declareId
				let form = await this.$u.api.showVipForm({
					declareId: this.declareId
				})
				if (this.vipType == 1) { //1个人
					//类别回显
					if (form.applyCategory) {
						form.applyCategory = JSON.parse(form.applyCategory)
						this.$refs.GrForm.list.forEach(item => {
							form.applyCategory.forEach(ele => {
								if (ele == item.name) {
									item.checked = true
								}
							})
						})
						form.applyCategory = JSON.stringify(form.applyCategory)
					}
					console.log(form, '回显表格', this.$refs.GrForm)
					this.$refs.GrForm.form = form
					console.log(vipTypeList, '查询可以申报的vip(个人)')
				} else {
					this.$refs.QyForm.form = form
					this.$refs.QyForm.form.typeName = form.declareName
					if (this.vipTypeList.length != 0) {
						console.log(vipTypeList, '查询可以申报的vip')
						this.$refs.QyForm.confirmType([{
							value: e.vipTypeId
						}])
					}
				}

			}

		},
		methods: {}
	}
</script>

<style lang="scss" scoped>
	.course-form-box {}
</style>
